const Router = require('@koa/router');

const { auth } = require('@middleware/auth.middleware');

const {
  userRegisterValidator,
  verifyRegister,
  verifyLogin,
  crpytPassword,
  changePwdValidator,
} = require('./user.middleware');

const { register, login, rePassword } = require('./user.controller');

const router = new Router({ prefix: '/users' });

const authRouter = new Router();

authRouter.use(auth);

// 注册
router.post(
  '/register',
  userRegisterValidator,
  verifyRegister,
  crpytPassword,
  register
);

// 登录
router.post('/login', userRegisterValidator, verifyLogin, login);

// 修改密码
authRouter.patch('/rePassword', changePwdValidator, crpytPassword, rePassword);

router.use(authRouter.routes());

module.exports = router;
